////////////////////////////////////////////////////////////////////////////////
// Filename: graphicsclass.cpp
////////////////////////////////////////////////////////////////////////////////
#include "GraphicsClass.h"


GraphicsClass::GraphicsClass(bool f,bool v)
	:Component(COMP_GRAPHICS),
	m_fullScreen(f),
	m_vsyncEnable(v),
	m_screenHeight(0),
	m_screenWidth(0),
	m_Device(),
	m_renderObjectManager()
{
}


GraphicsClass::GraphicsClass(const GraphicsClass& other)
	:Component(COMP_GRAPHICS)
{
}


GraphicsClass::~GraphicsClass()
{
}

void GraphicsClass::AddedToObject()
{
	RequestMessage(MSG_INITIAL,&GraphicsClass::Initialize);
}

void GraphicsClass::Initialize(const Message & msg)
{
	HINSTANCE hInstance;
	HWND hWnd;
	AuxUnGroupArgus(msg.p,hInstance,hWnd,m_screenWidth,m_screenHeight);
	m_Device=boost::make_shared<DeviceClass>(m_fullScreen,m_vsyncEnable);
	AddLocalComponent(m_Device);

	m_renderObjectManager=boost::make_shared<RenderObjectManager>();
	AddLocalComponent(m_renderObjectManager);

	
	//RenderInit();
}

bool GraphicsClass::Frame()
{
	Render();
	SendMessage(MSG_PRESENT);
	return true;
}

void GraphicsClass::RenderInit()
{
}

bool GraphicsClass::Render()
{
	D3D11_VIEWPORT vp;
	vp.Width = (FLOAT)m_screenWidth;
	vp.Height = (FLOAT)m_screenHeight;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
	m_renderObjectManager->Render();
	SendMessage(MSG_PRESENT);
	SendMessage(MSG_DUMP_ALL_MESSAGE);
	return true;
}